﻿@model FunnelWeb.Web.Views.Wiki.PageModel
@{
    // This is the default template that renders a blog post.
    // The actual "Page" does nothing except render the body of the post and meta data.
    Layout = "~/Views/Shared/_Public.cshtml";
}

@section Meta {
  <meta name="description" content="@Model.Entry.MetaDescription" />
  <meta name="keywords" content="@Model.Entry.TagsCommaSeparated" />
  <link rel="canonical" href="@Html.Qualify(Html.ActionUrl("Page", new { page = Model.Entry.Name }))" />
  <link rel="pingback" href="@Html.Qualify("/pingback")" />
  @if (Model.IsPriorVersion)
  {
    <meta name="robots" content="noindex, nofollow" />
  }
}

@section Summary {
  @Html.DisplayFor(model => model.Entry.Summary)
}

@if (Model.Entry.Status == FunnelWeb.Model.EntryStatus.Private)
{
  <div class='validation-summary-errors'>
    This is a <strong>private</strong> page. Only logged in users will be able to see
    it.
    @Html.ActionLink("Edit this page ", "Edit", "WikiAdmin", new { Area = "Admin", page = Model.Page }, new { })
    to make it public.
  </div>    
}
@if (!Model.Entry.HideChrome)
{
  <h1>
    @Html.ActionLink(Model.Entry.Title, "Page", new { page = Model.Entry.Name })
  </h1>
  <div class="entry-date">
    <span class='month'>@Model.Entry.Published.ToLocalTime().ToString("MMM d")</span>
    <span class='year'>@Model.Entry.Published.ToLocalTime().ToString("yyyy")</span>
  </div>
}
<div class="entry-container">
  @if (!Model.Entry.HideChrome && Model.IsPriorVersion)
  {
    <div class='entry-tools'>
      <div>
        <span>You are looking at revision @Model.Entry.LatestRevision.RevisionNumber of this
          page, which may be out of date. @Html.ActionLink("View the latest version.", "Page", new { page = Model.Entry.Name })</span>
        @if (ViewData.IsLoggedIn())
        {
          <span>@Html.ActionLink("Revert to this version.", "Revert", "WikiAdmin", new { Area = "Admin", page = Model.Page, revision = Model.Entry.LatestRevision.RevisionNumber }, new { })</span>
        }
        <span></span>
      </div>
    </div>
  }
 
  @RenderBody()

  @if (!Model.Entry.HideChrome)
  {
    if (Html.Settings().FacebookLike)
    {
    <div class="facebook">
      <iframe src="http://www.facebook.com/plugins/like.php?href=@Url.Encode(Request.Url.AbsoluteUri)&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true">
      </iframe>
    </div>
    }
  
    @TagList.Render(Model.Entry.Tags)
  
    <div class='entry-tools'>
      <span>Last revised: <a href="@Html.ActionUrl("Page", new { page = Model.Page.ToString(), revision = Model.Entry.LatestRevision.RevisionNumber })">@Html.Date(Model.Entry.LatestRevision.Revised)</a></span>
      <span>@Html.ActionLink("History", "Revisions", new { page = Model.Page })</span>
      @if (ViewData.IsLoggedIn())
      {
      
        <span>@Html.ActionLink("Edit", "Edit", "WikiAdmin", new { Area = "Admin", page = Model.Page }, new { })</span>
      }
      @if (Model.IsPriorVersion)
      {
        <div>
          <span>You are looking at revision @Model.Entry.LatestRevision.RevisionNumber of this
            page, which may be out of date. @Html.ActionLink("View the latest version.", "Page", new { page = Model.Entry.Name })</span>
        </div>
      }
    </div>
      if (Model.Entry.Pingbacks.Count > 0)
      {
    <div class="trackbacks">
      <h2>
        Trackbacks</h2>
      <ul>
        @foreach (var pingback in Model.Entry.Pingbacks.Where(x => !x.IsSpam))
        {
          <li>@Html.Encode(pingback.TargetTitle) | <a href="@Html.AttributeEncode(pingback.TargetUri)">@Html.Encode(pingback.TargetUri)</a></li>
        }
      </ul>
    </div>
      }
  }
  else
  {
    if (ViewData.IsLoggedIn())
    {
    <div class='entry-tools'>
      <span>@Html.ActionLink("Edit", "Edit", "WikiAdmin", new { Area = "Admin", page = Model.Page }, new { })</span>
    </div>
    }
  }
</div>
<div class="clear">
</div>
@if (Model.Entry.IsDiscussionEnabled)
{
  <div class="comments">
    <div class="comments-in">
      <a name="comments"></a>
      <h2>
        Discussion</h2>
      @if (Model.Entry.Comments.Count == 0)
      {
        <div class="empty">
          <p>
            No comments yet. Be the first!</p>
        </div>
      }
      @foreach (var comment in Model.Entry.Comments.Where(x => !x.IsSpam))
      {
        <div class="comment">
          <a name="comment-@comment.Id"></a>
          <div class="comment-author vcard">
            <img class="gravatar photo" src="@Html.Gravatar(comment.AuthorEmail)" alt="@Html.Encode(comment.AuthorName)" />
            <br />
            @Html.UrlLink(comment.AuthorUrl, comment.AuthorName, "fn url")
          </div>
          <div class="comment-body">
            <div class="comment-date">@Html.Date(comment.Posted)</div>
            @Html.DisplayFor(_ => comment.Body, new { Sanitize = true })
          </div>
          <div class="clear">
          </div>
        </div>
      }
    </div>
  </div>

      if (Html.Settings().DisableCommentsOlderThan > 0 && DateTime.UtcNow.AddDays(-Html.Settings().DisableCommentsOlderThan) > Model.Entry.Published)
      {
  <p>
    No new comments are allowed on this post.</p>  
      }
      else
      {
  <h2>
    Your Comments</h2>
      
  @Html.ValidationSummary("Comment unsuccessful. Please correct the errors below.")

  <div class='entry-comment'>
    @using (Html.BeginForm("Page", "Wiki", new { page = Model.Page }, FormMethod.Post, new { @class = "promptBeforeUnload" }))
    {
      <div class="form-body">
        <div class="editor-label">
          @Html.LabelFor(m => m.CommenterName)
        </div>
        <div class="editor-field">
          @Html.TextBoxFor(m => m.CommenterName, Html.AttributesFor(m => m.CommenterName))
          @Html.ValidationMessageFor(m => m.CommenterName)
          @Html.HintFor(m => m.CommenterName)
        </div>
        <div class="editor-label">
          @Html.LabelFor(m => m.CommenterBlog)
        </div>
        <div class="editor-field">
          @Html.TextBoxFor(m => m.CommenterBlog, Html.AttributesFor(m => m.CommenterBlog))
          @Html.ValidationMessageFor(m => m.CommenterBlog)
          @Html.HintFor(m => m.CommenterBlog)
        </div>
        <div class="editor-label">
          @Html.LabelFor(m => m.CommenterEmail)
        </div>
        <div class="editor-field">
          @Html.TextBoxFor(m => m.CommenterEmail, Html.AttributesFor(m => m.CommenterEmail))
          @Html.ValidationMessageFor(m => m.CommenterEmail)
          @Html.HintFor(m => m.CommenterEmail)
        </div>
        <div class="editor-label">
          @Html.LabelFor(m => m.Comments)
        </div>
        <div class="editor-field">
          @Html.EditorFor(m => m.Comments, Html.AttributesFor(m => m.Comments))
          @Html.ValidationMessageFor(m => m.Comments)
          @Html.HintFor(m => m.Comments)
        </div>
        <div class="editor-field">
          <input type="submit" id="submit" class="submit" value="Submit" />
        </div>
      </div>
    }
  </div>
  <h3>
    Preview</h3>
  <div id="wmd-preview" class="wmd-panel">
  </div>
      }

}
